package com.ui.table;

import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;

/**
 * 表格第一列，序号突出显示
 * 
 * @author phx
 *
 */
public class RowHeadRender extends JLabel implements TableCellRenderer {

	private static final long serialVersionUID = -77608456654644254L;

	public RowHeadRender(JTable table) {
		JTableHeader header = table.getTableHeader();
		setOpaque(true);// 是否是不透明的
		setBorder(UIManager.getBorder("TableHeader.cellBorder"));
		setHorizontalAlignment(CENTER);
		setForeground(header.getForeground());
		setBackground(header.getBackground());
		setFont(header.getFont());
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
			int row, int column) {
		setText(value == null ? "" : value.toString());
		return this;
	}
}